package indi.jp.project.business.pub.controller;

import indi.jp.project.business.pub.pojo.po.OfficePO;
import indi.jp.project.business.pub.pojo.query.OfficeQuery;
import indi.jp.project.business.pub.service.OfficeService;
import indi.jp.project.core.entity.JsonResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 办事处
 *
 * @author jiangping
 * @date 2022/6/5
 */
@RestController
@RequestMapping("/pub/office")
public class OfficeController {

    @Resource
    private OfficeService officeService;

    @GetMapping("/grid")
    public JsonResult queryGrid(OfficeQuery query) throws Exception {
        return officeService.queryGrid(query);
    }

    @PostMapping("/save")
    public JsonResult save(@RequestBody OfficePO officePO, HttpServletRequest request) throws Exception {
        String account = request.getParameter("account");
        officePO.setCreateBy(account);
        officePO.setModifyBy(account);
        return officeService.save(officePO);
    }

    @GetMapping("/find")
    public JsonResult findById(@RequestParam String id) throws Exception {
        return officeService.findById(id);
    }

    @PostMapping("/delete")
    public JsonResult deleteById(@RequestParam String id) throws Exception {
        return officeService.deleteById(id);
    }
}
